﻿document.write('' +
    '<!-- 表单优化插件 -->' +
    '<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/forms/jquery.validationEngine-cn.js"></script>' +
    '<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/forms/jquery.validationEngine.js"></script>' +
    '<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/forms/autogrowtextarea.js"></script>' +
    '<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/forms/jquery.serializejson.js"></script>' +
    '<!-- 表单提交&验证插件 -->' +
    '<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/wizard/jquery.form.js"></script>' +
    '<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/wizard/jquery.validate.min.js"></script>' +
    //'<script type="text/javascript" src="/Areas/Admin/HTML/js/plugins/wizard/jquery.form.wizard.js"></script>' +
    '');

var submitlock = false;
var loadingid;
function customvalidation() {
    return true;
}

$(function () {

    //===== 验证引擎 =====//
    $(".formvalidator").validationEngine({
        ajaxFormValidationMethod: 'POST',
        ajaxFormValidation: true,
        //表单提交验证通过后，Ajax 提交之前的回调函数
        onBeforeAjaxFormValidation: function (form, options) {
            ///自定义验证
            submitlock = true;
            loadingid = elayer.loading();
            var cv = customvalidation();
            if (!cv) {
                elayer.close(loadingid);
                submitlock = false;
            }
            return cv;
        },
        //表单提交验证完成时的回调函数，form：表单元素 valid：验证结果（ture or false）
        onValidationComplete: function (form, valid) {
        },
        onAjaxFormComplete: function (form, data) {
            elayer.close(loadingid);
            //判断是否有ajax结果处理方法
            if (form.data('ajaxcallback')) {
                eval(form.data('ajaxcallback'))(data);
            }
                //操作失败
            else if (!data.status) {
                //如有验证码，刷新 验证码
                if (form.find("#img-verifycode").length > 0) {
                    $("#img-verifycode").trigger('click');
                }
                //失败回调方法
                if (form.data('failure')) {
                    eval(form.data('failure'))(data);
                } else {
                    elayer.alert('错误 ', data.errmsg);
                }
            }
                //操作成功
            else if (data.status) {
                //成功提示文本
                if (form.data('successmsg')) {
                    elayer.alert('提示', form.data('successmsg'));
                }
                    //成功跳转
                else if (form.data('successurl')) {
                    window.location.href = form.data('successurl');
                }
                    //成功回调方法
                else if (form.data('successcallback')) {
                    eval(form.data('successcallback'))(data);
                } else {
                    if (data.data) elayer.alert('提示', data.data);
                    else elayer.alert('提示', '保存成功.');
                }
            }
        }
    });

    //===== Form 控件提示语 =====//
    $('input[placeholder], textarea[placeholder]').placeholder();

});